package logic

import (
	"context"
	"errors"
	"novel-kit/model/mysql"

	"novel-kit/novelrpc/internal/svc"
	"novel-kit/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookDeskShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookDeskShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookDeskShowLogic {
	return &BookDeskShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 书架查询
func (l *BookDeskShowLogic) BookDeskShow(in *novelrpc.BookDeskShowRequest) (*novelrpc.BookDeskShowResponse, error) {
	// todo: add your logic here and delete this line

	var userfind mysql.User
	if err := userfind.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}
	var findBookDesk []*novelrpc.BookDeskShow

	findBookDesk = mysql.FindBookDeskByUserId(mysql.DB, in.UserId)

	return &novelrpc.BookDeskShowResponse{
		List: findBookDesk,
	}, nil
}
